﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Net;

namespace DAO
{
    class ChuoiKetNoi
    {
        public static SqlConnection con = null;
        public static SqlCommand cmd = null;
        public static SqlDataAdapter da;
        public static DataSet ds;
        public static SqlCommandBuilder cmb = null;
        public static SqlDataReader dr = null;
        public static void Openconnect()
        {


            string connect = @"Data Source=MYPC\SQLEXPRESS;Initial Catalog=QL_BongDa;Integrated Security=True";
            con = new SqlConnection(connect);
            con.Open();
        }
         public static void Closeconnect()
        {
                string connect = @"Data Source=MYPC\SQLEXPRESS;Initial Catalog=QL_BongDa;Integrated Security=True";
                con = new SqlConnection(connect);
                con.Close();

        }
        public static void exc(string sql)
        {
            Openconnect();
            SqlCommand cmd = new SqlCommand(sql, con);
            cmd.CommandText = sql;
            cmd.ExecuteNonQuery();
            Closeconnect();

        }
        //HAM DOC DU LIEU CHUYEN VAO DATASET
        public static DataTable laybang(string sql)
        {
            // string sql = "SELECT MaNV,TenNV,TaiKhoan,Quyen FROM NHANVIEN";
            cmd = new SqlCommand(sql, con);
            da = new SqlDataAdapter(cmd);
            cmb = new SqlCommandBuilder(da);
            ds = new DataSet();
            da.Fill(ds);
            return ds.Tables[0];

        }
        public static SqlDataReader check_ma(string str)
        {
            // ChuoiKetNoi.Openconnect();
            cmd = new SqlCommand(str, con);
            SqlDataReader dr = cmd.ExecuteReader();
            // ChuoiKetNoi.Closeconnect();
            return dr;
        }
        public static DataSet getsource(string sql)
        {
            da = new SqlDataAdapter(sql, con);
            ds = new DataSet();
            da.Fill(ds);
            return ds;
        }
        public static SqlDataReader exereader(string sql)
        {
            //ChuoiKetNoi.Openconnect();
            cmd = new SqlCommand(sql, con);
            return cmd.ExecuteReader();
            // ChuoiKetNoi.Closeconnect();
        }

    
    }
}
